#!/usr/bin/env python
# -*- coding: utf-8 -*-
#$Id$
"""
Gui dialog wrappers.
"""

from PyQt4 import QtCore, QtGui

from sys import path
path.append('..')
import progress_ui

class Progress(QtGui.QDialog):
	def __init__(self, parent=None):
		QtGui.QDialog.__init__(self, parent)

		self.ui = progress_ui.Ui_ProgressUI()
		self.ui.setupUi(self)
		self.ui.text.hide()
		self.ui.text.setAcceptRichText(False)
		self.layout().setSizeConstraint(QtGui.QLayout.SetFixedSize)
		self.center()
		# translation
		self.setWindowTitle(self.tr('Samizat update'))
		self._exit_text = self.tr('    Exit')


	def retranslateUi(self):
		"""
		Should be called on LanguageChange event
		"""
		self.ui.retranslateUi(self)
		self.setWindowTitle(self.tr('Samizat update'))
		self._exit_text = self.tr('    Exit')

	def changeEvent(self, event):
		"""
		Override for self re-translation support
		"""
		# language changed: retransalte self
		if event == QtCore.QEvent.LanguageChange:
			self.retranslateUi()
		else:
			QtGui.QWidget.changeEvent(self, event)


	def center(self):
		screen = QtGui.QDesktopWidget().availableGeometry()
		size =  self.geometry()
		self.move((screen.width()-size.width())/2,
			(screen.height()-size.height())/2)

	def progress1(self, msg=None, value=None):
		try:
			if msg != None: self.ui.label_1.setText(msg)
			if value != None: self.ui.progressBar_1.setValue(value)
		except:
			pass

	def progress2(self, msg=None, value=None):
		try:
			if msg != None: self.ui.label_2.setText(msg)
			if value != None: self.ui.progressBar_2.setValue(value)
		except:
			pass

	def progress3(self, msg=None):
		try:
			if msg != None and msg.strip():
				self.ui.text.append(u"%s" % (msg,))
		except:
			pass

	def cancel2exit(self):
		"""
		Change icon and caption from 'cancel' to 'exit'
		"""
		icon1 = QtGui.QIcon()
		icon1.addPixmap(QtGui.QPixmap(":/img/tick_circle_frame.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
		self.ui.bCancel.setIcon(icon1)
		self.ui.bCancel.setText(self._exit_text)


if __name__=="__main__":
	import sys
	app = QtGui.QApplication(sys.argv)

	dlg = Progress()
	dlg.center()
	dlg.show()
	app.exec_()
